package com.project.collectAPI.controller;


import com.project.collectAPI.comm.R;
import com.project.collectAPI.comm.SpiderTools;
import com.project.collectAPI.entity.Savedata;
import com.project.collectAPI.service.SavedataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("api")
public class apiController {

    @Resource
    private SavedataService savedataService;

    //删除
    @PostMapping(value = {"/delete"})
    public R delete() throws IOException {
        try {
            savedataService.ClearAllProducts();
            return R.ok("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(400,e.getMessage().toString());
        }
    }


    //更新
    @PostMapping(value = {"/updateData"})
    public R updateData(@RequestBody Savedata savedata) throws IOException {
        try {
            savedataService.updateById(savedata);
            return R.ok("更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(400,e.getMessage().toString());
        }
    }


}
